package org.jahia.sqlprofiler.gui;

import javax.swing.JPanel;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowEvent;
import org.jCharts.chartData.ChartDataException;
import org.jCharts.properties.PropertyException;
import org.jCharts.properties.PieChart2DProperties;
import org.jCharts.properties.LegendProperties;
import org.jCharts.properties.ChartProperties;
import org.jCharts.chartData.PieChartDataSet;
import org.jCharts.nonAxisChart.PieChart2D;
import org.jCharts.axisChart.AxisChart;
import org.jCharts.test.TestDataGenerator;
import org.jCharts.properties.LineChartProperties;
import org.jCharts.properties.PointChartProperties;
import org.jCharts.chartData.AxisChartDataSet;
import org.jCharts.types.ChartType;
import org.jCharts.properties.AxisProperties;
import org.jCharts.chartData.DataSeries;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Iterator;
import org.jahia.sqlprofiler.QueryEntry;
import org.jCharts.Chart;
import org.apache.log4j.Category;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: Jahia Ltd</p>
 * @author not attributable
 * @version 1.0
 */

public class ChartPanel extends JPanel implements ChartModelListener {

    /** used to log messages **/
    private static final Category LOG =
        Category.getInstance(ChartPanel.class);

    private Chart chart;
    private ChartModel chartModel;

    public ChartPanel(ChartModel chartModel) throws
        ChartDataException, PropertyException {
        chartModel.addChartModelListener(this);
        this.chartModel = chartModel;
    }

    public void paint(Graphics graphics) {

        chart = chartModel.getChart(this.getSize());

        if (chart != null) {
            try {
                chart.setGraphics2D( (Graphics2D) graphics);
                chart.render();
            } catch (Exception pe) {
                pe.printStackTrace();
            } 
        }
    }

    public void chartDataChanged(ChartModelEvent e) {
        ChartModel chartModel = (ChartModel) e.getSource();
        this.chartModel = chartModel; // in case it changed !
        this.repaint();
    }

}